<template>
  <div class="app-container">
    <div class="filter-container bor-container">
      <el-form size="mini" :inline="true">
        <!--<el-form-item>
          <el-select placeholder="公告类型" @change="query()" clearable v-model="formInline.kind">
            <el-option value="1" label="使用帮助"></el-option>
            <el-option value="2" label="陪玩管理规则"></el-option>
            <el-option value="3" label="公会管理规则"></el-option>
            <el-option value="4" label="平台通知"></el-option>
            <el-option value="5" label="活动公告"></el-option>
          </el-select>
        </el-form-item>-->
       <!-- <el-button size="mini" @click="query()" icon="el-icon-search">查询</el-button>-->
      </el-form>
    </div>
    <div class="filter-container btn-right">
      <el-button size="mini"  type="primary" @click="openAdd()" icon="el-icon-plus">添加</el-button>
    </div>
    <el-table class="per_tb" stripe v-loading="loading" border :data="tableData">
      <el-table-column
        type="index"
        width="50"
      label="序号">
      </el-table-column>

      <el-table-column prop="title" label="标题">
      </el-table-column>

      <el-table-column prop="content" label="内容">

      </el-table-column>

      <el-table-column prop="createTime" label="创建时间">
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button  size="mini" type="warning" @click="openEdit(scope.row)" icon="el-icon-edit-outline" >编辑</el-button>
          <el-button  size="mini" type="warning" @click="openDetail(scope.row)" icon="el-icon-edit-outline" >删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      class="pagination-right"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageNum"
      :page-sizes="[10]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="formInline.total">
    </el-pagination>
    <blog-edit
      @close="close"
      @success="success"
      v-if="dialogadd.status"
      :model="data"
      :dialog_="dialogadd.status">
    </blog-edit>
  </div>
</template>
<script>
  import { getBlogListApi , deleteBlogApI} from "@/api/blog";
  import { mapGetters } from 'vuex'
  import RoleEdit from './components/BlogEdit'
  import BlogEdit from "./components/BlogEdit";
  export default {
    name: 'Blog',
    components: {BlogEdit, RoleEdit },
    data() {
      return {
        value: '',
        data:'',
        formInline: {
          page:1,
          pageSize: 10,
          pageNum: 1,
          total: 0,
          kind:''
        },
        editUser: null, // 编辑时传入的对象
        loading: false,
        tableData: [],
        dialog: {
          status: false
        },
        dialogadd: {
          status: false
        }
      }
    },
    computed: {
      ...mapGetters([
        'buttons',
      ])
    },
    mounted() {
      this.getList()
    },
    methods: {
      openAdd() {
        this.dialogadd.status = true
      },
      //增加编辑打开弹窗
      openEdit(obj) {
        this.dialogadd.status = true
        this.data = obj
      },
      // 详情打开弹窗
      openDetail(obj) {
        this.$confirm('是否删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          obj.delLoading = true;
          deleteBlogApI({ id: obj.id}).then(res => {
            obj.delLoading = false;
            if (res.code === 200) {
              this.$emit('success');
              this.$message.success('操作成功');
              this.getList();
            } else {
              this.$message.error(res.message);
            }
          });
        });
      },
      // 操作栏中的下拉框发生修改

      // 点击查询事件
      query() {
        this.formInline.pageNum = 1
        this.getList()
      },
      // 操作成功的钩子用来更新列表
      success() {
        this.getList()
      },
      // 关闭弹窗返回的钩子
      close() {
        this.dialog.status = false;
        this.dialogadd.status = false;
      },

      // pageSize发生改变触发
      handleSizeChange(val) {
        this.pageNum = 1
        this.pageSize = val
        this.getList()
      },
      // pageNum 发生改变触发
      handleCurrentChange(val) {
        this.formInline.pageNum = val
        this.getList()
      },
      // 删除用户
      onDelete(id, usernameParam,index) {
        this.$confirm('是否删除该用户?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // adminDeleteAPI(id,usernameParam).then(res => {
          //   if (res.code === 200) {
          //     this.$message.success(res.message)
          //     this.getUserList()
          //   } else {
          //     this.$message.error(res.message)
          //   }
          // })
        }).catch(() => {

        });
      },
      // 获取公告列表
      getList() {
        this.loading = true
        getBlogListApi(this.formInline).then(res => {
          debugger
          this.loading = false
          if (res.code === 200) {
            this.tableData = res.data.list
            this.formInline.total = res.data.total
            this.dialogadd.status = false
          } else {
            this.$message.error(res.message)
          }
        })
      }
    }
  }
</script>
<style>
  .userCount{
    background-color: rgba(242, 242, 242, 1);
    height: 45px;
    line-height: 45px;
    margin-left: 38px;
    font-size: 14px;
  }
  .userCount span {
    margin-right: 40px;
    margin-left: 14px;
  }
  .input_co{
    margin-left:38px;
  }
  .input_co1{
    margin-left:0px;
  }
  .input_s{
    width:70px;
  }
  .el-date-editor.input_s.el-input.el-input--mini.el-input--prefix.el-input--suffix.el-date-editor--datetime {
    width: 125px;
  }
  .per_tb{
    margin-top: 15px;
    margin-left: 38px;
    width:97.8%;
  }
  .pagination-right.el-pagination.is-background {
    margin-left: 36px;
    margin-top: 5px;
  }

</style>

